Skip to content

Conversation

@gmarouli
Copy link
Contributor

The downsampling operation is editing the source mapping to replace gauge metrics with an aggregate type which contains the pre-aggregated data.

However, the process does not respect the disabled subobjects configured by parent fields, for example, a passthrough field and gets conflicts as it tried to reconstruct the updated mapping.

For example, the following valid mapping section:

     "metrics": {
        "type": "passthrough",
        "priority": 10,
        "dynamic": "true",
        "properties": {
          "k8s.volume.inodes": {
            "type": "long",
            "time_series_metric": "gauge"
          },
          "k8s.volume.inodes.free": {
            "type": "long",
            "time_series_metric": "gauge"
          },
          "k8s.volume.inodes.used": {
            "type": "long",
            "time_series_metric": "gauge"
          }
        }
      }

gets converted to:

          "metrics.k8s.volume.inodes": {
            "type": "aggregate_metric_double",
            "time_series_metric": "gauge",
            ....
          },
          "metrics.k8s.volume.inodes.free": {
            "type": "aggregate_metric_double",
            "time_series_metric": "gauge",
          ...
          },
          "metrics.k8s.volume.inodes.used": {
            "type": "aggregate_metric_double",
            "time_series_metric": "gauge",
            ...
          }

Which is not valid because the disabled subobjects is not set anymore.

This PR (re)proposes to use the visitor pattern to update the source mapping in place. Last time we proposed that there was a better solution; however, now we see that the original structure of the mapping is important for inherited properties.

Fixes: #138572

@gmarouli gmarouli requested a review from kkrik-es November 27, 2025 09:29
@gmarouli gmarouli added >bug auto-backport Automatically create backport pull requests when merged :StorageEngine/Downsampling Downsampling (replacement for rollups) - Turn fine-grained time-based data into coarser-grained data branch:9.2 labels Nov 27, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@elasticsearchmachine
Copy link
Collaborator

Hi @gmarouli, I've created a changelog YAML for you.

private static void copyMapping(Map<String, ?> sourceMapping, Map<String, Object> updatedMapping) {
for (String f : sourceMapping.keySet()) {
if (f.equals(PROPERTIES) == false && f.equals(MULTI_FIELDS) == false) {
updatedMapping.put(f, sourceMapping.get(f));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copies meta objects, correct? Let's cover in a test (if not already).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meta and other parameters such as scaling_factor etc.

Map<String, Object> downsampledMapping = new HashMap<>();
for (Map.Entry<String, Object> entry : sourceIndexMappings.entrySet()) {
if (entry.getKey().equals(PROPERTIES) == false) {
downsampledMapping.put(entry.getKey(), entry.getValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? Maybe add a comment?

);

HashMap<String, Object> result = new HashMap<>();
MappingVisitor.visitAndCopyMapping(expectedProperties, result, (ignored, source, dest) -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we also add a test that creates random mappings and checks that the copied one is a clone of the source?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

gmarouli and others added 2 commits November 28, 2025 09:37
@gmarouli
Copy link
Contributor Author

Update:

I am currently working on the ci failures. The problem is that we need to be able to distringuish and handle differently a multi field from a subobjects false field :) Working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :StorageEngine/Downsampling Downsampling (replacement for rollups) - Turn fine-grained time-based data into coarser-grained data Team:StorageEngine v9.2.3 v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Downsampling fails to handle indices with mappings that have dotted fields with subobjects false.

3 participants